package com.richest.api.controller.cn.order;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.richest.api.controller.form.OrderForm;
import com.richest.api.service.IClientOrderService;
import com.richest.bean.OrderMasterBean;
import com.richest.bean.OrderSubBanquetBean;
import com.richest.bean.OrderSubBean;
import com.richest.bean.OrderSubCommodityBean;
import com.richest.bean.OrderSubDiscountBean;
import com.richest.bean.OrderSubFullReductionBean;
import com.richest.util.CallResults;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

/**
 * API接口 客户端 订单功能服务接口
 * 
 * @author 杨博
 * @version com.richest.api 2.0
 */
@RestController
@RequestMapping("/ClientOrderManagerController")
@Api(value = "客户端 订单功能服务接口")
@EnableAutoConfiguration
public class ApiClientOrderManageController {

	@Autowired
	private IClientOrderService service;

	@RequestMapping(value = "placeOrder", produces = "application/json;charset=UTF-8")
	@ApiOperation(notes = "用户下单", value = "用户下单", httpMethod = "POST")
	@ApiImplicitParam(name = "orderForm", value = "订单表单", required = true, paramType = "body", dataType = "OrderForm")
	public CallResults placeOrder(@RequestBody OrderForm orderForm) {
		Map<String, Object> map = service.placeOrder(orderForm);
		if (map != null) {
			return CallResults.ok().put("IdMaps", map);
		} else {
			return CallResults.error().put("message", "错误，下单失败！");
		}
	}

	@RequestMapping(value = "cancelMasterOrder", produces = "application/json;charset=UTF-8")
	@ApiOperation(notes = "用户取消主订单", value = "用户取消主订单", httpMethod = "POST")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "orderMasterId", value = "主订单id", paramType = "body", dataType = "java.lang.Long"),
			@ApiImplicitParam(name = "StatusId", value = "订单当前状态id", paramType = "body", dataType = "java.lang.Long"),
			@ApiImplicitParam(name = "userId", value = "操作用户id", paramType = "body", dataType = "java.lang.Long"),
			@ApiImplicitParam(name = "remarks", value = "备注信息", paramType = "body", dataType = "String") })
	public CallResults cancelMasterOrder(@RequestBody Long orderMasterId, @RequestBody Long StatusId,
			@RequestBody Long userId, @RequestBody String remarks) {
		if (service.cancelMasterOrder(orderMasterId, StatusId, userId, remarks)) {
			return CallResults.ok();
		} else {
			return CallResults.error().put("message", "错误，用户取消主订单失败！");
		}
	}

	@RequestMapping(value = "cancelSubOrder", produces = "application/json;charset=UTF-8")
	@ApiOperation(notes = "用户取消子订单", value = "用户取消子订单", httpMethod = "POST")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "orderSubId", value = "子订单id", paramType = "body", dataType = "java.lang.Long"),
			@ApiImplicitParam(name = "StatusId", value = "订单当前状态id", paramType = "body", dataType = "java.lang.Long"),
			@ApiImplicitParam(name = "userId", value = "操作用户id", paramType = "body", dataType = "java.lang.Long"),
			@ApiImplicitParam(name = "remarks", value = "备注信息", paramType = "body", dataType = "String") })
	public CallResults cancelSubOrder(@RequestBody Long orderSubId, @RequestBody Long StatusId,
			@RequestBody Long userId, @RequestBody String remarks) {
		if (service.cancelSubOrder(orderSubId, StatusId, userId, remarks)) {
			return CallResults.ok();
		} else {
			return CallResults.error().put("message", "错误，用户取消子订单失败！");
		}
	}

	@RequestMapping(value = "userConfirmationCancelMasterOrder", produces = "application/json;charset=UTF-8")
	@ApiOperation(notes = "商家取消主订单用户确认", value = "商家取消主订单用户确认", httpMethod = "POST")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "orderMasterId", value = "主订单id", paramType = "body", dataType = "java.lang.Long"),
			@ApiImplicitParam(name = "StatusId", value = "订单当前状态id", paramType = "body", dataType = "java.lang.Long"),
			@ApiImplicitParam(name = "userId", value = "操作用户id", paramType = "body", dataType = "java.lang.Long"),
			@ApiImplicitParam(name = "remarks", value = "备注信息", paramType = "body", dataType = "String") })
	public CallResults userConfirmationCancelMasterOrder(@RequestBody Long orderMasterId, @RequestBody Long StatusId,
			@RequestBody Long userId, @RequestBody String remarks) {
		if (service.userConfirmationCancelMasterOrder(orderMasterId, StatusId, userId, remarks)) {
			return CallResults.ok();
		} else {
			return CallResults.error().put("message", "错误，商家取消主订单用户确认失败！");
		}
	}

	@RequestMapping(value = "userConfirmationCancelSubOrder", produces = "application/json;charset=UTF-8")
	@ApiOperation(notes = "商家取消子订单用户确认", value = "商家取消子订单用户确认", httpMethod = "POST")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "orderSubId", value = "子订单id", paramType = "body", dataType = "java.lang.Long"),
			@ApiImplicitParam(name = "StatusId", value = "订单当前状态id", paramType = "body", dataType = "java.lang.Long"),
			@ApiImplicitParam(name = "userId", value = "操作用户id", paramType = "body", dataType = "java.lang.Long"),
			@ApiImplicitParam(name = "remarks", value = "备注信息", paramType = "body", dataType = "String") })
	public CallResults userConfirmationCancelSubOrder(@RequestBody Long orderSubId, @RequestBody Long StatusId,
			@RequestBody Long userId, @RequestBody String remarks) {
		if (service.userConfirmationCancelMasterOrder(orderSubId, StatusId, userId, remarks)) {
			return CallResults.ok();
		} else {
			return CallResults.error().put("message", "错误，商家取消子订单用户确认失败！");
		}
	}

	@RequestMapping(value = "finishMasterOrder", produces = "application/json;charset=UTF-8")
	@ApiOperation(notes = "用户结束主订单", value = "用户结束主订单", httpMethod = "POST")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "orderMasterId", value = "主订单id", paramType = "body", dataType = "java.lang.Long"),
			@ApiImplicitParam(name = "StatusId", value = "订单当前状态id", paramType = "body", dataType = "java.lang.Long"),
			@ApiImplicitParam(name = "userId", value = "操作用户id", paramType = "body", dataType = "java.lang.Long"),
			@ApiImplicitParam(name = "remarks", value = "备注信息", paramType = "body", dataType = "String") })
	public CallResults finishMasterOrder(@RequestBody Long orderMasterId, @RequestBody Long StatusId,
			@RequestBody Long userId, @RequestBody String remarks) {
		if (service.userConfirmationCancelMasterOrder(orderMasterId, StatusId, userId, remarks)) {
			return CallResults.ok();
		} else {
			return CallResults.error().put("message", "错误，用户结束主订单失败！");
		}
	}

	@RequestMapping(value = "finishSubOrder", produces = "application/json;charset=UTF-8")
	@ApiOperation(notes = "用户结束子订单", value = "用户结束子订单", httpMethod = "POST")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "orderSubId", value = "子订单id", paramType = "body", dataType = "java.lang.Long"),
			@ApiImplicitParam(name = "StatusId", value = "订单当前状态id", paramType = "body", dataType = "java.lang.Long"),
			@ApiImplicitParam(name = "userId", value = "操作用户id", paramType = "body", dataType = "java.lang.Long"),
			@ApiImplicitParam(name = "remarks", value = "备注信息", paramType = "body", dataType = "String") })
	public CallResults finishSubOrder(@RequestBody Long orderSubId, @RequestBody Long StatusId,
			@RequestBody Long userId, @RequestBody String remarks) {
		if (service.userConfirmationCancelMasterOrder(orderSubId, StatusId, userId, remarks)) {
			return CallResults.ok();
		} else {
			return CallResults.error().put("message", "错误，用户结束子订单失败！");
		}
	}

	@RequestMapping(value = "orderMasterSelectOneById", produces = "application/json;charset=UTF-8")
	@ApiOperation(notes = "通过id获取主订单Bean", value = "通过id获取主订单Bean", httpMethod = "GET")
	@ApiImplicitParam(name = "id", value = "主订单id", required = true, paramType = "query", dataType = "java.lang.Long")
	public CallResults orderMasterSelectOneById(Long id) {
		OrderMasterBean bean = service.orderMasterSelectOneById(id);
		if (bean != null) {
			return CallResults.ok().put("OrderMasterBean", bean);
		} else {
			return CallResults.error().put("message", "获取主订单信息失败！");
		}
	}

	@RequestMapping(value = "orderMasterSelectListByUserId", produces = "application/json;charset=UTF-8")
	@ApiOperation(notes = "通过用户id获取主订单Bean集合", value = "通过用户id获取主订单Bean集合", httpMethod = "GET")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "userId", value = "用户id", paramType = "query", dataType = "java.lang.Long"),
			@ApiImplicitParam(name = "pageNumber", value = "第几页", paramType = "query", dataType = "Integer"),
			@ApiImplicitParam(name = "pageSize", value = "页大小", paramType = "query", dataType = "Integer") })
	public CallResults orderMasterSelectListByUserId(Long userId, Integer pageNumber, Integer pageSize) {
		List<OrderMasterBean> beans = service.orderMasterSelectListByUserId(userId, (pageNumber - 1) * pageSize,
				pageNumber * pageSize);
		if (beans != null) {
			return CallResults.ok().put("OrderMasterBeanList", beans);
		} else {
			return CallResults.error().put("message", "获取主订单信息集合失败！");
		}
	}

	@RequestMapping(value = "orderSubSelectOneById", produces = "application/json;charset=UTF-8")
	@ApiOperation(notes = "通过id获取主订单Bean", value = "通过id获取主订单Bean", httpMethod = "GET")
	@ApiImplicitParam(name = "id", value = "子订单id", required = true, paramType = "query", dataType = "java.lang.Long")
	public CallResults orderSubSelectOneById(Long id) {
		OrderSubBean bean = service.orderSubSelectOneById(id);
		if (bean != null) {
			return CallResults.ok().put("OrderSubBean", bean);
		} else {
			return CallResults.error().put("message", "获取子订单信息失败！");
		}
	}

	@RequestMapping(value = "orderSubSelectListByOrderMasterId", produces = "application/json;charset=UTF-8")
	@ApiOperation(notes = "获取子订单Bean集合", value = "获取子订单Bean集合", httpMethod = "GET")
	@ApiImplicitParam(name = "orderMasterId", value = "主订单id", required = true, paramType = "query", dataType = "java.lang.Long")
	public CallResults orderSubSelectListByOrderMasterId(Long orderMasterId) {
		List<OrderSubBean> beans = service.orderSubSelectListByOrderMasterId(orderMasterId);
		if (beans != null) {
			return CallResults.ok().put("OrderSubBeanList", beans);
		} else {
			return CallResults.error().put("message", "获取子订单信息集合失败！");
		}
	}

	@RequestMapping(value = "orderSubBanquetSelectOneById", produces = "application/json;charset=UTF-8")
	@ApiOperation(notes = "获取子订单包房桌信息", value = "获取子订单包房桌信息", httpMethod = "GET")
	@ApiImplicitParam(name = "id", value = "获取子订单包房桌信息id", required = true, paramType = "query", dataType = "java.lang.Long")
	public CallResults orderSubBanquetSelectOneById(Long id) {
		OrderSubBanquetBean bean = service.orderSubBanquetSelectOneById(id);
		if (bean != null) {
			return CallResults.ok().put("OrderSubBanquetBean", bean);
		} else {
			return CallResults.error().put("message", "获取子订单包房桌信息失败！");
		}
	}

	@RequestMapping(value = "orderSubBanquetSelectListByOrderSubId", produces = "application/json;charset=UTF-8")
	@ApiOperation(notes = "获取子订单包房桌信息集合", value = "获取子订单包房桌信息集合", httpMethod = "GET")
	@ApiImplicitParam(name = "orderSubId", value = "子订单id", required = true, paramType = "query", dataType = "java.lang.Long")
	public CallResults orderSubBanquetSelectListByOrderSubId(Long orderSubId) {
		List<OrderSubBanquetBean> beans = service.orderSubBanquetSelectListByOrderSubId(orderSubId);
		if (beans != null) {
			return CallResults.ok().put("OrderSubBanquetBeanList", beans);
		} else {
			return CallResults.error().put("message", "获取子订单包房桌信息集合失败！");
		}
	}

	@RequestMapping(value = "orderSubCommoditySelectOneById", produces = "application/json;charset=UTF-8")
	@ApiOperation(notes = "获取子订单商品信息", value = "获取子订单商品信息", httpMethod = "GET")
	@ApiImplicitParam(name = "id", value = "获取子订单商品信息id", required = true, paramType = "query", dataType = "java.lang.Long")
	public CallResults orderSubCommoditySelectOneById(Long id) {
		OrderSubCommodityBean bean = service.orderSubCommoditySelectOneById(id);
		if (bean != null) {
			return CallResults.ok().put("OrderSubCommodityBean", bean);
		} else {
			return CallResults.error().put("message", "获取子订单商品信息失败！");
		}
	}

	@RequestMapping(value = "orderSubCommoditySelectListByOrderSubId", produces = "application/json;charset=UTF-8")
	@ApiOperation(notes = "获取子订单商品信息集合", value = "获取子订单商品信息集合", httpMethod = "GET")
	@ApiImplicitParam(name = "orderSubId", value = "子订单id", required = true, paramType = "query", dataType = "java.lang.Long")
	public CallResults orderSubCommoditySelectListByOrderSubId(Long orderSubId) {
		List<OrderSubCommodityBean> beans = service.orderSubCommoditySelectListByOrderSubId(orderSubId);
		if (beans != null) {
			return CallResults.ok().put("OrderSubCommodityBeanList", beans);
		} else {
			return CallResults.error().put("message", "获取子订单商品信息集合失败！");
		}
	}

	@RequestMapping(value = "orderSubDiscountSelectOneById", produces = "application/json;charset=UTF-8")
	@ApiOperation(notes = "获取子订单优惠信息", value = "获取子订单优惠信息", httpMethod = "GET")
	@ApiImplicitParam(name = "id", value = "获取子订单优惠信息id", required = true, paramType = "query", dataType = "java.lang.Long")
	public CallResults orderSubDiscountSelectOneById(Long id) {
		OrderSubDiscountBean bean = service.orderSubDiscountSelectOneById(id);
		if (bean != null) {
			return CallResults.ok().put("OrderSubDiscountBean", bean);
		} else {
			return CallResults.error().put("message", "获取子订单优惠信息失败！");
		}
	}

	@RequestMapping(value = "orderSubDiscountSelectListByOrderSubId", produces = "application/json;charset=UTF-8")
	@ApiOperation(notes = "获取子订单优惠信息集合", value = "获取子订单优惠信息集合", httpMethod = "GET")
	@ApiImplicitParam(name = "orderSubId", value = "子订单id", required = true, paramType = "query", dataType = "java.lang.Long")
	public CallResults orderSubDiscountSelectListByOrderSubId(Long orderSubId) {
		List<OrderSubDiscountBean> beans = service.orderSubDiscountSelectListByOrderSubId(orderSubId);
		if (beans != null) {
			return CallResults.ok().put("OrderSubDiscountBeanList", beans);
		} else {
			return CallResults.error().put("message", "获取子订单优惠信息集合失败！");
		}
	}

	@RequestMapping(value = "orderSubFullReductionSelectOneById", produces = "application/json;charset=UTF-8")
	@ApiOperation(notes = "获取子订单满减信息", value = "获取子订单满减信息", httpMethod = "GET")
	@ApiImplicitParam(name = "id", value = "获取子订单满减信息id", required = true, paramType = "query", dataType = "java.lang.Long")
	public CallResults orderSubFullReductionSelectOneById(Long id) {
		OrderSubFullReductionBean bean = service.orderSubFullReductionSelectOneById(id);
		if (bean != null) {
			return CallResults.ok().put("OrderSubFullReductionBean", bean);
		} else {
			return CallResults.error().put("message", "获取子订单满减信息失败！");
		}
	}

	@RequestMapping(value = "orderSubFullReductionSelectListByOrderSubId", produces = "application/json;charset=UTF-8")
	@ApiOperation(notes = "获取子订单满减信息集合", value = "获取子订单优惠信息集合", httpMethod = "GET")
	@ApiImplicitParam(name = "orderSubId", value = "子订单id", required = true, paramType = "query", dataType = "java.lang.Long")
	public CallResults orderSubFullReductionSelectListByOrderSubId(Long orderSubId) {
		List<OrderSubFullReductionBean> beans = service.orderSubFullReductionSelectListByOrderSubId(orderSubId);
		if (beans != null) {
			return CallResults.ok().put("OrderSubFullReductionBeanList", beans);
		} else {
			return CallResults.error().put("message", "获取子订单优惠信息集合失败！");
		}
	}

}
